package kr.hkit.androidcomplete02.ch19;

import kr.hkit.androidcomplete02.R;
import kr.hkit.androidcomplete02.R.id;
import kr.hkit.androidcomplete02.R.layout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ThreadTest extends Activity {
	int mainValue = 0;
	int backValue = 0;
	TextView mMainText;
	TextView mBackText;
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch19_threadtest);
		
		mMainText = (TextView)findViewById(R.id.ch19_mainvalue);
		mBackText = (TextView)findViewById(R.id.ch19_backvalue);
		
		BackThread thread = new BackThread();
		thread.setDaemon(true);
		thread.start();
		
	}
	
	public void mOnClick(View v){
		
		if(v.getId() == R.id.ch19_increase){
			mainValue++;
			mMainText.setText("MainValue : " + mainValue);
			mBackText.setText("BackValue : " + backValue);
		}
	}
	
	class BackThread extends Thread{

		@Override
		public void run() {
			while(true){
				backValue++;
				//mBackText.setText("BackValue : " + backValue);
				try {
					sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
			}
		}
		
	}
}
